<template>
    <div>
      <h2>Header</h2>
      <p>当前我的定价是{{ price }}</p>
    </div>
  </template>
  
  <script>
  import pubsub from "pubsub-js";
  export default {
    name: "Header",
    data() {
      return {
        price: 200,
      };
    },
    mounted() {
      //一般我们在初始化阶段的时候就会订阅数据了
      pubsub.subscribe("changePrice", this.changePriceHandle);
    },
    methods: {
      //订阅changePrice的函数
      changePriceHandle(_, value) {
        // console.log(value);
        this.price += value;
      },
    },
  };
  </script>
  
  <style></style>